package site.wetsion.galio.auth.endpoints;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import site.wetsion.galio.data.entity.PlatformDO;
import site.wetsion.galio.data.service.PlatformService;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 自定义授权页
 *
 * @author wetsion
 * @version 1.0
 * @CLassName GrantEndpoint
 * @date 2019/6/14 11:36 AM
 */
@Controller
@SessionAttributes("authorizationRequest")
public class GrantEndpoint {

    @Autowired
    PlatformService platformService;

    @RequestMapping("/oauth/confirm_access")
    public ModelAndView getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) {
        AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");
        ModelAndView view = new ModelAndView();
        view.setViewName("grant");
        view.addObject("clientId", authorizationRequest.getClientId());
        PlatformDO platformDO = platformService.getById(Long.parseLong(authorizationRequest.getClientId()));
        view.addObject("clientName", platformDO.getNameCn());
        return view;
    }
}
